const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let n;
let initArr = [];
rl.addListener("line", (line) => {
    if (n === undefined) {
        n = Number(line.trim())
    } else {
        initArr.push(line.split(" ").map(Number));
        if (initArr.length === n) {
            getResult(initArr, n);

            // 清理数据
            n = undefined;
            initArr.length = 0
        }
    }
})

/**
 * @param initArr { [[number]] } 二维数组,表示幻方信息
 * @param n n阶幻方
 * @return {void} 无返回值
 */
function getResult(initArr, n) {
    // 找出每列和应该的值
    const total = initArr.reduce((acc, arr) => {
        return acc + arr.reduce((acc2, num) => acc2 + num, 0)
    }, 0)
    const unitSum = total / n;

    // 判断可能需要交换的点
    let errorRow = []  // 出错的行角标
    let errorCol = [] // 出错的列角标
    initArr.forEach((arr, index) => {
        if (arr.reduce((acc, num) => acc + num, 0) !== unitSum) {
            errorRow.push(index)
        }
    })
    for (let i = 0; i < n; i++) {
        let sum = 0;
        for (let j = 0; j < n; j++) {
            sum += initArr[j][i];
        }
        if (sum !== unitSum) {
            errorCol.push(i)
        }
    }

    // 计算需要相交的点
    let errorPoints = [];
    if (errorRow.length && errorCol.length) { // 对角点交换
        errorPoints.push([[errorRow[0], errorCol[0]], [errorRow[1], errorCol[1]]])
        errorPoints.push([[errorRow[1], errorCol[0]], [errorRow[0], errorCol[1]]])
    } else if (errorRow.length) { // 纵向有点交换
        for (let i = 0; i < n; i++) {
            errorPoints.push([[errorRow[0], i], [errorRow[1], i]])
        }
    } else if (errorCol.length) { // 横向有点交换
        for (let i = 0; i < n; i++) {
            errorPoints.push([[i, errorCol[0]], [i, errorCol[1]]])
        }
    }

    // 验证
    let result;
    for (const points of errorPoints) {
        let tempInitArr = JSON.parse(JSON.stringify(initArr));
        let pointsA = [...points[0]]
        let pointsB = [...points[1]]
        let tempValue = tempInitArr[pointsA[0]][pointsA[1]]
        tempInitArr[pointsA[0]][pointsA[1]] = tempInitArr[pointsB[0]][pointsB[1]]
        tempInitArr[pointsB[0]][pointsB[1]] = tempValue
        if (valid(tempInitArr, unitSum)) {
            result = [pointsA, pointsB]
            break;
        }
    }
    result.sort((point1, point2) => {
        if (point1[0] === point2[0]) {
            return point1[1] - point2[1]
        } else {
            return point1[0] - point2[0]
        }
    })
    console.log(result[0][0] + 1, result[0][1] + 1, initArr[result[1][0]][result[1][1]])
    console.log(result[1][0] + 1, result[1][1] + 1, initArr[result[0][0]][result[0][1]])

    // 验证交换点
    function valid(tempInitArr, unitSum) {
        for (let i = 0; i < n; i++) { // 横
            let arr = tempInitArr[i]
            if (arr.reduce((acc, num) => acc + num, 0) !== unitSum) {
                return false;
            }
        }

        for (let i = 0; i < n; i++) { // 纵
            let sum = 0;
            for (let j = 0; j < n; j++) { // 纵
                sum += tempInitArr[j][i]
            }
            if (sum !== unitSum) {
                return false;
            }
        }
        return true
    }
}
